FROM my-ubuntu:14.04
#此images的tags为my-php:5.5
#安装在/usr/src/php 
# see：https://github.com/docker-library/php/blob/master/5.5/Dockerfile
# 如果是php -a运行则run时必须加-t参数
# docker run --name php-5.5 --volumes-from share_volume -v /Users/github/docker_lnmp/php5.5/conf/conf:/usr/src/php/conf/ -v /Users/github/docker_lnmp/php5.5/conf/ext/:/usr/src/php/ext/ -v /Users/github/docker_lnmp/php5.5/conf/etc/:/usr/src/php/etc/ -v /Users/github/docker_lnmp/php5.5/src/:/usr/src/php/php-ext/ -p 9000:9000 -d my-php:5.5


MAINTAINER aogg


# 可被删除的依赖
RUN buildDeps=" \
		libxml2-dev \
		xz-utils \
	" \
	&& apt update && apt install -y \
		# persistent / runtime deps
		ca-certificates librecode0 libsqlite3-0 jq \
		# phpize deps
		autoconf file libc-dev pkg-config re2c \
		$buildDeps \
		--no-install-recommends \

	&& rm -r /var/lib/apt/lists/*


# 可自定义的配置
# 安装文件目录
ARG PHP_CONFIGURE_DIR='/usr/local/php'
ARG PHP_DIR='/usr/src/php'
ARG PHP_VERSION='5.5.36'
ARG PHP_CONFIGURE_ARGS='--enable-fpm'
ARG PHP_SHA256='e1bbe33d6b4da66b15c483131520a9fc505eeb6629fa70c5cfba79590a1d0801'
ARG PHP_GPG_KEYS='0B96609E270F565C13292B24C13C70B87267B52D 0BD78B5F97500D450838F95DFE857D9A90D90EC1 F38252826ACD957EF380D39F2F7956BC5DA04B5D'
ARG PHP_PROCESSES_NUM=15




# 创建目录
# 各国地址会不一样
# http://php.net/get/php-5.5.36.tar.gz/from/a/mirror
# http://cn2.php.net/get/php-5.5.36.tar.gz/from/this/mirror
# http://cn2.php.net/get/php-5.5.36.tar.gz.asc/from/this/mirror
RUN PHP_FILENAME="php-${PHP_VERSION}.tar.xz" \ 
	&& PHP_INI_DIR="${PHP_DIR}/conf" \


	&& php_down_url='http://php.net/get' \
	&& curl -fSL "${php_down_url}/${PHP_FILENAME}/from/this/mirror" -o "$PHP_FILENAME" \
	# && echo "$PHP_SHA256 *${PHP_FILENAME}" | sha256sum -c - \
	# && curl -fSL "${php_down_url}/$PHP_FILENAME.asc/from/this/mirror" -o "${PHP_FILENAME}.asc" \
	# 认证
	# && gpg --verify "$PHP_FILENAME.asc" \
	# && export GNUPGHOME="$(mktemp -d)" \
	# && for key in $PHP_GPG_KEYS; do \
	# 	gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
	# done \
	# && gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" \
	# && rm -r "$GNUPGHOME" "$PHP_FILENAME.asc" \


	&& mkdir -p $PHP_CONFIGURE_DIR $PHP_DIR $PHP_INI_DIR/conf.d \
	&& tar -xf "$PHP_FILENAME" -C $PHP_CONFIGURE_DIR --strip-components=1 \
	# 删除压缩包
	&& rm -rf ${PHP_FILENAME}* \
	&& cd $PHP_CONFIGURE_DIR \
	# 安装php
	&& ./configure \
		--prefix=$PHP_DIR \
		# 指定php.ini位置
		--with-config-file-path="$PHP_INI_DIR" \
		--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
		# --disable-cgi \
		# 开启fpm
		# --enable-fpm \
		# 开启mysqlnd驱动
		--enable-mysqlnd \
		${PHP_CONFIGURE_ARGS} \
	&& make -j"$(nproc)" \
	&& make install \
	# 未知
	# && { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } \
	# 删除
	# && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -o APT::AutoRemove::SuggestsImportant=false $BUILDDEPS \
	&& make clean

# 添加环境变量
ENV PATH $PHP_DIR/bin:$PHP_DIR/sbin:$PATH


# 安装php扩展
COPY ./src/* ${PHP_CONFIGURE_DIR}/../php-ext/

ENV PHP_PROCESSES_NUM $PHP_PROCESSES_NUM
ENV PHP_CONFIGURE_DIR $PHP_CONFIGURE_DIR
# php-ext.sh不是一个可执行文件
# 添加执行权限，并添加到/bin/中
RUN php_ext_sh=${PHP_CONFIGURE_DIR}/../php-ext/php-ext.sh \
	&& chmod +x $php_ext_sh \
	&& ln -s $php_ext_sh /bin/php-ext.sh \
	&& /bin/bash $php_ext_sh



WORKDIR $PHP_DIR

EXPOSE 9000

VOLUME ["${PHP_DIR}/conf", "${PHP_DIR}/etc"]

##<autogenerated>##
#fpm用这个即可，-R运行root，解决mac远程windows的共享目录
CMD ["php-fpm", "-R"]
# 此cmd需要在run时加-t参数
# CMD ["php", "-a"]
##</autogenerated>##

